import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import React, { useEffect, useImperativeHandle, useState, } from "react";
import { Modal, Table, Row, Col, Button, Select, Spin, Checkbox, Tooltip, } from "antd";
import { ExclamationCircleOutlined } from "@ant-design/icons";
import notify from "devextreme/ui/notify";
import "./_style.less";
import { CpasIcon } from "~/public/cpas-ui";
import { numToString } from "../../tools/Tools";
import { resetPidIfNotFound, getCurrentSysName, SystemName, } from "../../tools/Tools";
import { saveImportExcelAPI, getLeftTreeList, getCpasTableByTids, autoMathExcelToSystemAPI, importExcelToColumnMatchAPI, getBaseDataApi, } from "../ExcelGrid/api/DesignTableApi";
import { LayoutB } from "~/public/cpas-ui";
import { TextBox } from "devextreme-react/text-box";
const ImportExcelModal = React.forwardRef((props, ref) => {
    const { title, okCallback, cancelCallback, dataId, type, adjustTipInfo } = props;
    // const [tableData, setTableData] = useState<any[]>([]);
    const [importExcelModalShow, setImportExcelModalShow] = useState(false);
    const [loadData, setLoadData] = useState([]);
    const [importData, setImportData] = useState([]);
    const [filterImportData, setFilterImportData] = useState([]); //经过筛选之后的导入数据
    const [excelCfgData, setExcelCfgData] = useState({});
    const [excelHeaderData, setExcelHeaderData] = useState([]);
    const [excelHeaderCmaps, setExcelHeaderCmaps] = useState([]);
    const [excelHiddenColumnIndexs, setExcelHiddenColumnIndexs] = useState([]);
    const [systemHeaderData, setSystemHeaderData] = useState([]);
    const [matchColumnsIndex, setMatchColumnsIndex] = useState([]);
    const [childTableData, setChildTableData] = useState([]);
    const [excelColumnInfo, setExcelColumnInfo] = useState({}); //设置excel列配置信息
    const [excelHmColumnData, setExcelHmColumnData] = useState([]);
    const [allMathColums, setAllMathColums] = useState([]); //存储所有节点匹配列的信息
    const [noteTitle, setNoteTitle] = useState("");
    const [noteLists, setNoteLists] = useState([]);
    const [totalInfo, setTotalInfo] = useState({});
    const [isLoading, setIsLoading] = useState(false);
    const [searchValue, setSearchValue] = useState([]);
    const [btnLoading, setBtnLoading] = useState(false);
    const [inputValue, setInputValue] = useState("");
    const [currentTname, setCurentTname] = useState("");
    const [repeatExcelModalShow, setRepeatExcelModalShow] = useState(false);
    const [repeatImportData, setRepeatImportData] = useState([]); //存储导入excel重复数据
    const [isForceImport, setForceImport] = useState(false); //是否是强制导入
    const getTempleteList = async (selData) => { };
    // 自定义方法
    useImperativeHandle(ref, () => ({
        /**
         * 导入
         * @param tname 表名：财务报表必传
         */
        openImportDialog: async (tname) => {
            setCurentTname(tname);
            await openImportDialog(tname);
        },
    }));
    const openImportDialog = async (tname) => {
        let electronComponents;
        if (window.parent) {
            electronComponents = window["parent"]["electronComponents"];
        }
        else {
            electronComponents = window["electronComponents"];
        }
        const dialog_result = await electronComponents.openFileDialog("xlsx");
        const checkFolderPath = dialog_result && dialog_result?.filePaths.length
            ? dialog_result?.filePaths[0]
            : null;
        console.log(dialog_result, "dialog_result");
        if (checkFolderPath) {
            props.loadingCallback && props.loadingCallback(true);
            try {
                let resData;
                if (tname === "附注") {
                    resData = await getLeftTreeList(dataId);
                }
                else {
                    resData = await getBaseDataApi("account.getFSTableNames", {
                        tableType: tname,
                    });
                    if (resData && resData.length) {
                        for (let i = 0; i < resData.length; i++) {
                            resData[i]["title"] = resData[i].name;
                            resData[i]["id"] = i;
                        }
                    }
                    console.log(resData, "resData---");
                }
                console.log(resData, "resData---");
                if (resData && resData.length) {
                    const dataTreee = resetPidIfNotFound(resData);
                    setNoteLists(dataTreee);
                }
            }
            catch (error) {
                props.loadingCallback && props.loadingCallback(false);
                props.errorCallback && props.errorCallback(error);
            }
            console.log(checkFolderPath, "checkFolderPath");
            try {
                const resList = await importExcelToColumnMatchAPI({
                    filePath: checkFolderPath,
                    type,
                    dataId,
                    tname,
                });
                props.loadingCallback && props.loadingCallback(false);
                if (resList && resList.length) {
                    const repeatData = getImportRepeatData(resList);
                    if (repeatData && repeatData.length) {
                        setRepeatExcelModalShow(true);
                        setRepeatImportData(repeatData);
                    }
                    else {
                        setImportExcelModalShow(true);
                    }
                    setLoadData(resList);
                    // return notify("匹配节点成功～", "success", 2000)
                }
                else {
                    return notify("匹配节点为空～", "error", 2000);
                }
            }
            catch (e) {
                props.loadingCallback && props.loadingCallback(false);
                props.errorCallback && props.errorCallback(e);
                notify("导入节点加载失败", "error", 2000);
                throw e;
            }
        }
    };
    //获取导入重复的数据
    const getImportRepeatData = (data) => {
        if (!data || !data.length) {
            return [];
        }
        let result = [];
        for (let i = 0; i < data.length; i++) {
            const { excelNoteName, excelCfg } = data[i];
            const repeatData = excelCfg?.repeatData;
            if (repeatData && repeatData.length) {
                for (let j = 0; j < repeatData.length; j++) {
                    result.push({
                        ...repeatData[j],
                        sheetName: excelCfg?.sheetName,
                        noteName: excelNoteName,
                    });
                }
            }
        }
        return result;
    };
    const handleSelectChange = async (value, record) => {
        console.log(`selected ${value}`);
        const res = importData.filter((item) => item?.systemNoteName === value);
        if (res && res.length) {
            return notify("所选节点名称已被重复选择～", "warning", 1000);
        }
        console.log(importData, "importData selectData", record);
        let index = 0;
        let newSystemNoteName = "";
        // let oldSystemNoteName = "";
        let excelNoteName = "";
        let newTid = "";
        let mathColumnsIndex = [];
        for (let i = 0; i < importData.length; i++) {
            const { excelCfg = {}, systemNoteName } = importData[i];
            if (excelCfg.noteName === record.name) {
                // oldSystemNoteName = systemNoteName;
                importData[i]["systemNoteName"] = value;
                const res = noteLists.filter((item) => item.title === value);
                if (res && res.length) {
                    index = i;
                    newSystemNoteName = value;
                    excelNoteName = excelCfg.noteName;
                    const tid = res[0].fid || res[0].tid;
                    importData[i]["tid"] = tid;
                    const getCpasRes = await getCpasTableByTids({
                        tids: [tid],
                        type,
                        dataType: "json",
                        isToZl: false,
                        dataGridType: "source",
                    });
                    const allCpasData = getCpasRes?.data;
                    if (allCpasData && allCpasData[tid]) {
                        const { data: cpasData, headerColumn } = allCpasData[tid];
                        const mathResult = await autoMathExcelToSystemAPI({
                            excelCfg: {
                                cmapColumnCmapData: excelCfg?.cmapColumnCmapData,
                                hmCfgData: excelCfg?.hmCfgData,
                            },
                            cpasCfg: {
                                data: cpasData,
                                headerColumn,
                            },
                        });
                        mathColumnsIndex =
                            mathResult && mathResult.length ? mathResult : [];
                        console.log(mathColumnsIndex, "mathColumnsIndex----");
                        importData[i]["mathColumnsIndex"] = mathColumnsIndex;
                        importData[i]["tid"] = tid;
                        newTid = tid;
                        importData[i]["cpasCfg"] = allCpasData[tid];
                    }
                    else {
                        importData[i]["mathColumnsIndex"] = [];
                        importData[i]["tid"] = tid;
                        importData[i]["cpasCfg"] = null;
                    }
                }
            }
        }
        setImportData(importData);
        if (newSystemNoteName) {
            const { unmatchedNum, matchedNum } = totalInfo;
            setTotalInfo({
                ...totalInfo,
                unmatchedNum: unmatchedNum > 1 ? unmatchedNum - 1 : 0,
                matchedNum: matchedNum + 1,
            });
            onRowClick(importData[index], importData);
            // onRowClick(tableData[index], importData);
            setMatchColumnsIndex(mathColumnsIndex);
            updateAllMathColums(mathColumnsIndex);
        }
    };
    const columns = [
        {
            title: "Excel表名",
            dataIndex: "name",
            key: "name",
            width: "40%",
            render: (value) => {
                return (_jsx(Tooltip, { placement: "top", title: value, children: _jsx("div", { className: "table-name", children: type === "fs" && value ? value.split("-")[1] : value }) }));
            },
        },
        {
            title: "对应的系统表名",
            dataIndex: "systemNoteName",
            key: "systemNoteName",
            render: (value, record) => {
                let options = [];
                for (let i = 0; i < noteLists.length; i++) {
                    const { title } = noteLists[i];
                    options.push({
                        value: title,
                        label: title,
                        // label: type === "fs" && title ? title.split("-")[1] : title,
                    });
                }
                return (_jsx(Select, { allowClear: true, showSearch: true, style: { width: "98%" }, onChange: (e) => handleSelectChange(e, record), tokenSeparators: [","], defaultValue: value, options: options }));
            },
        },
        {
            title: "列是否已对应",
            dataIndex: "status",
            key: "status",
            width: "20%",
            align: "center",
            render: (value, record) => {
                let tdVal = "否";
                const res = importData.filter((item) => item?.excelNoteName === record.name);
                if (res && res.length) {
                    const { excelCfg: { headerData, excelData, cmapColumnCmapData }, mathColumnsIndex, } = res[0];
                    if (headerData && headerData.length) {
                        const excelHeader = headerData.filter((value) => value !== null && value !== undefined && value !== "");
                        const isVisible = mathColumnsIndex &&
                            mathColumnsIndex.length &&
                            excelHeader &&
                            excelHeader.length
                            ? true
                            : false;
                        let isMatch = isVisible
                            ? excelHeader.length === mathColumnsIndex.length
                            : false;
                        //列map长度是否相等
                        if (cmapColumnCmapData &&
                            mathColumnsIndex &&
                            cmapColumnCmapData.length &&
                            mathColumnsIndex.length &&
                            cmapColumnCmapData.length === mathColumnsIndex.length) {
                            isMatch = true;
                        }
                        if (isMatch) {
                            tdVal = "是";
                        }
                    }
                    if (!excelData || !excelData.length) {
                        tdVal = "空表";
                    }
                }
                return tdVal;
            },
        },
    ];
    const initReload = async () => {
        console.log(loadData, "loadData---");
        const data = [];
        let allMathColumsData = [];
        let totalInfo = {
            totalNum: loadData.length || 0,
            unmatchedNum: 0,
            matchedNum: 0, //已匹配节点
        };
        for (let i = 0; i < loadData.length; ++i) {
            const { excelCfg, systemNoteName, tid } = loadData[i];
            loadData[i] = {
                ...loadData[i],
                key: i.toString(),
                name: excelCfg?.noteName,
                systemNoteName,
                status: "是",
                className: i === 0 ? "highlight-row" : "normal-row",
            };
            if (tid) {
                totalInfo.matchedNum++;
            }
            else {
                totalInfo.unmatchedNum++;
            }
        }
        setTotalInfo(totalInfo);
        onRowClick(loadData[0], loadData); //设置表格默认第一行选中状态
        // setTableData(data);
        setImportData(loadData);
        // setAllMathColums(allMathColumsData);
    };
    const onRowClick = (record, resData) => {
        console.log("onRowClick", record, resData);
        const allData = resData ? resData : importData; //兼容表格设置默认第一行设置点击状态数据展示
        const data = allData.filter((item) => item?.excelCfg?.noteName === record?.name);
        if (data && data.length) {
            const { excelCfg, cpasCfg, mathColumnsIndex, excelHmColumnData, systemNoteName, } = data[0];
            // excelCfg && setExcelCfgData(excelCfg);
            if (excelCfg?.headerData) {
                setExcelHeaderData(excelCfg?.headerData);
            }
            else {
                setExcelHeaderData([]);
            }
            if (excelCfg?.cmapColumnCmapData) {
                setExcelHeaderCmaps(excelCfg?.cmapColumnCmapData);
            }
            else {
                setExcelHeaderCmaps([]);
            }
            if (excelCfg?.hiddenColumnIndexs) {
                setExcelHiddenColumnIndexs(excelCfg?.hiddenColumnIndexs);
            }
            else {
                setExcelHiddenColumnIndexs([]);
            }
            setNoteTitle(excelCfg?.noteName);
            setSystemHeaderData(cpasCfg?.headerColumn);
            setMatchColumnsIndex(mathColumnsIndex);
            // setExcelHmColumnData(excelHmColumnData);
            for (let i = 0; i < importData.length; i++) {
                const { name } = importData[i];
                if (name === record?.name) {
                    importData[i]["className"] = "highlight-row";
                }
                else {
                    importData[i]["className"] = "";
                }
            }
            setImportData(importData);
            // setTableData(tableData);
            setExcelColumnInfo({});
        }
    };
    const onExcelColClick = (colIndex, value) => {
        // const isHm = excelHmColumnData.includes(colIndex);
        setExcelColumnInfo({
            columnIndex: colIndex,
            columnVal: value,
            // isHm, //是否是豁免列
        });
    };
    const renderExcelCol = (data) => {
        let res = [];
        for (let i = 0; i < data.length; i++) {
            if (i > 0 &&
                !excelHiddenColumnIndexs.includes(i) &&
                (data[i] || (excelHeaderCmaps && excelHeaderCmaps[i]))) {
                res.push(_jsxs(Col, { className: excelColumnInfo?.columnIndex === i
                        ? "excel-col excel-col-active"
                        : "excel-col", span: 6, onClick: (e) => onExcelColClick(i, data[i]), children: [_jsx("span", { children: numToString(i + 1) }), data[i]] }, i));
            }
        }
        return res;
    };
    const renderExcelRow = () => {
        const excelHeader = excelHeaderData || [];
        if (!excelHeader || !excelHeader.length) {
            return _jsx("div", { children: "\u6682\u65E0Excel\u5217\u4FE1\u606F" });
        }
        return _jsx(Row, { children: renderExcelCol(excelHeader) });
    };
    const updateAllMathColums = (mathColumn) => {
        let newAllMathColumns = allMathColums.slice();
        const isFilterData = newAllMathColumns.filter((item) => item?.excelNoteName === noteTitle);
        if (isFilterData && isFilterData.length) {
            for (let i = 0; i < newAllMathColumns.length; i++) {
                const { excelNoteName } = newAllMathColumns[i];
                if (excelNoteName === noteTitle) {
                    newAllMathColumns[i]["matchColumnsIndex"] = mathColumn;
                }
            }
        }
        else {
            const res = importData.filter((item) => item?.excelCfg?.noteName === noteTitle);
            if (res && res.length) {
                const { excelCfg, systemNoteName, matchColumnsIndex, tid } = res[0];
                newAllMathColumns.push({
                    excelNoteName: excelCfg?.noteName,
                    systemNoteName,
                    matchColumnsIndex: mathColumn,
                    tid,
                });
            }
        }
        setAllMathColums(newAllMathColumns);
    };
    //取消系统关联
    const onSystemCancelCorrelation = (e, systemColIndex, isHm) => {
        let result = [];
        for (let i = 0; i < matchColumnsIndex.length; i++) {
            const res = matchColumnsIndex[i].split("-");
            if (+res[1] === systemColIndex &&
                ((isHm && res[2]) || (!isHm && !res[2]))) {
            }
            else {
                result.push(matchColumnsIndex[i]);
            }
        }
        console.log(result, "取消关联结果 result");
        for (let i = 0; i < importData.length; i++) {
            const { excelCfg, excelNoteName } = importData[i];
            if (excelNoteName === noteTitle) {
                importData[i]["mathColumnsIndex"] = result;
            }
        }
        console.log("onSystemCancelCorrelation", importData);
        setMatchColumnsIndex(result);
        updateAllMathColums(result);
        // setAllMathColums(allMathColums);
        setImportData(importData);
        e.stopPropagation();
    };
    const onSystemClick = (systemColIndex, isSystemHm) => {
        console.log("onSystemClick");
        const { columnIndex } = excelColumnInfo;
        for (let i = 0; i < matchColumnsIndex.length; i++) {
            const res = matchColumnsIndex[i].split("-");
            if (+res[0] === columnIndex || +res[1] === systemColIndex) {
                return notify("当前列已对应，如需变更请先取消系统列的关联～", "warning", 1000);
            }
        }
        if (!columnIndex) {
            return notify("请选择Excel列字段进行对应", "warning", 1000);
        }
        let val = `${columnIndex}-${systemColIndex}`;
        if (isSystemHm) {
            val = `${columnIndex}-${systemColIndex}-isHm`;
        }
        matchColumnsIndex.push(val);
        setMatchColumnsIndex(matchColumnsIndex);
        setExcelColumnInfo({});
        updateAllMathColums(matchColumnsIndex);
        // setAllMathColums(allMathColums);
    };
    //关联项目列
    const renderSystemToExcelCol = (systemColIndex, isHm) => {
        console.log("renderSystemToExcelCol");
        if (!matchColumnsIndex || !matchColumnsIndex.length) {
            return (_jsx("div", { className: "column-data", children: _jsx("div", { className: "column-no-data", children: "\u5C1A\u672A\u5BF9\u5E94" }) }));
        }
        for (let i = 0; i < matchColumnsIndex.length; i++) {
            if (matchColumnsIndex[i]) {
                const res = matchColumnsIndex[i].split("-");
                //0是excel的列，1是系统列，2有值的情况下是豁免列
                if (+res[1] === systemColIndex &&
                    ((isHm && res[2]) || (!isHm && !res[2]))) {
                    return (_jsxs("div", { className: "column-data", children: [_jsx("div", { className: "excel-name", children: excelHeaderData[res[0]] }), _jsx("span", { title: "\u53D6\u6D88\u5BF9\u5E94", style: { cursor: "pointer" }, onClick: (e) => onSystemCancelCorrelation(e, systemColIndex, isHm), children: _jsx(CpasIcon, { style: { marginLeft: 10 }, type: "icon-close", color: "red" }) })] }));
                }
            }
        }
        return (_jsx("div", { className: "column-data", children: _jsx("div", { className: "column-no-data", children: "\u5C1A\u672A\u5BF9\u5E94" }) }));
    };
    const renderSystemCol = (data) => {
        let res = [];
        for (let i = 0; i < data.length; i++) {
            const { label } = data[i];
            if (i > 0 && i < data.length - 1) {
                const isHm = data[i]?.config?.p_exclude ? true : false; //是否是豁免
                const hidden = data[i]?.config?.hidden ? true : false;
                if (!hidden) {
                    res.push(_jsx(Col, { span: 6, children: _jsxs("div", { className: "note-table-td", children: [_jsx("div", { className: "num", children: numToString(i + 1) }), _jsxs("div", { className: "note-column-ri", onClick: () => onSystemClick(i, isHm), children: [_jsx("div", { className: "column-name", children: label }), _jsx("div", { className: "column-content", children: renderSystemToExcelCol(i, isHm) })] })] }) }, i));
                }
            }
        }
        return res;
    };
    const renderSystemRow = () => {
        if (!systemHeaderData || !systemHeaderData.length) {
            return _jsx("div", { children: "\u6682\u65E0\u7CFB\u7EDF\u5217\u4FE1\u606F" });
        }
        return _jsx(Row, { children: renderSystemCol(systemHeaderData) });
    };
    const rowClassName = (record, index) => {
        return record.className || "normal-row";
    };
    const onConfirm = async () => {
        //用户没有操作手动匹配，只用执行自动匹配
        //执行手动匹配
        console.log(allMathColums, "allMathColums-----");
        try {
            setIsLoading(true);
            setBtnLoading(true);
            const res = await saveImportExcelAPI({
                type,
                dataId,
                manualColumnsIndex: allMathColums,
                isForceImport,
            });
            console.log(res, "res----");
            setIsLoading(false);
            if (res && res.ok) {
                setImportExcelModalShow(false);
                setInputValue("");
                setForceImport(false);
                notify("Excel导入成功～", "success", 1000);
                clearImportModalData();
                return props.okCallback && (await props.okCallback());
            }
            else if (res.msg) {
                setBtnLoading(false);
                setIsLoading(false);
                return notify(res.msg, "error", 1000);
            }
        }
        catch (e) {
            setBtnLoading(false);
            setIsLoading(false);
            return notify("导入出错了! 请重试～", "error", 1000);
        }
    };
    const onSearchChange = (list) => {
        console.log(list, "list----");
        //只要包含未对应的表
        if (list.includes("noTable")) {
            let res = [];
            for (let i = 0; i < importData.length; i++) {
                const { systemNoteName } = importData[i];
                if (!systemNoteName) {
                    res.push(importData[i]);
                }
            }
            setFilterImportData(res);
        }
        //只勾选未对应的列
        if (!list.includes("noTable") && list.includes("noColumn")) {
            let res = [];
            for (let i = 0; i < importData.length; i++) {
                const { excelCfg: { headerData, cmapColumnCmapData }, mathColumnsIndex, } = importData[i];
                if (headerData && headerData.length) {
                    const excelHeader = headerData.filter((value) => value !== null && value !== undefined && value !== "");
                    const isVisible = mathColumnsIndex &&
                        mathColumnsIndex.length &&
                        excelHeader &&
                        excelHeader.length
                        ? true
                        : false;
                    let isMatch = isVisible
                        ? excelHeader.length === mathColumnsIndex.length + 1
                        : false;
                    //列map长度是否相等
                    if (cmapColumnCmapData &&
                        mathColumnsIndex &&
                        cmapColumnCmapData.length &&
                        mathColumnsIndex.length &&
                        cmapColumnCmapData.length === mathColumnsIndex.length) {
                        isMatch = true;
                    }
                    if (!isMatch) {
                        res.push(importData[i]);
                    }
                }
            }
            setFilterImportData(res);
        }
        //同时勾选未对应的表和列
        if (list.includes("noTable") && list.includes("noColumn")) {
            let res = [];
            for (let i = 0; i < importData.length; i++) {
                const { systemNoteName } = importData[i];
                if (!systemNoteName) {
                    res.push(importData[i]);
                }
            }
            setFilterImportData(res);
        }
        setSearchValue(list);
    };
    const clearImportModalData = () => {
        setBtnLoading(false);
        setImportData([]);
        setLoadData([]);
        setSearchValue([]);
        setImportExcelModalShow(false);
        setAllMathColums([]);
        setNoteTitle("");
        setSystemHeaderData([]);
        setMatchColumnsIndex([]);
        setExcelColumnInfo({});
        setInputValue("");
        setForceImport(false);
    };
    const onCancel = () => {
        Modal.confirm({
            title: "提示",
            icon: _jsx(ExclamationCircleOutlined, {}),
            content: "操作确认导入数据关联规则将全部丢失～",
            okText: "确认",
            cancelText: "取消",
            onOk: () => {
                clearImportModalData();
                props.cancelCallback && props.cancelCallback();
            },
        });
    };
    const onSearchValueChanged = async (data) => {
        const val = data.value;
        if (val) {
            setInputValue(val);
            let res = [];
            for (let i = 0; i < importData.length; i++) {
                const { excelNoteName } = importData[i];
                if (excelNoteName.includes(val)) {
                    res.push(importData[i]);
                }
            }
            setFilterImportData(res);
        }
        else {
            setInputValue("");
        }
    };
    useEffect(() => {
        console.log("useEffect");
        initReload();
    }, [loadData]);
    const { totalNum, unmatchedNum, matchedNum } = totalInfo;
    const leftCont = () => {
        return (_jsxs("div", { className: "import-excel-left", children: [_jsxs("div", { className: "import-modal-result", children: ["\u5171", _jsx("span", { children: totalNum }), "\u6761,\u672A\u5BF9\u5E94\u8868\u540D", _jsx("span", { className: "red", children: unmatchedNum }), "\u6761,\u5DF2\u5BF9\u5E94\u8868\u540D", _jsx("span", { children: matchedNum }), "\u6761"] }), _jsx("div", { className: "import-modal-search", children: _jsxs(Checkbox.Group, { onChange: onSearchChange, value: searchValue, children: [_jsx(Checkbox, { value: "noTable", children: "\u672A\u5BF9\u5E94\u7684\u8868" }), _jsx(Checkbox, { value: "noColumn", children: "\u672A\u5BF9\u5E94\u7684\u5217" })] }) }), _jsx("div", { className: "import-modal-input", children: _jsx(TextBox, { showClearButton: true, mode: "search", value: inputValue, onValueChanged: (e) => onSearchValueChanged(e) }) }), _jsx("div", { className: "import-table", children: _jsx(Table, { columns: columns, 
                        // expandable={{ expandedRowRender,  defaultExpandAllRows: true }}
                        dataSource: searchValue.length || inputValue ? filterImportData : importData, rowClassName: rowClassName, onRow: (record) => {
                            return {
                                onClick: (event) => onRowClick(record),
                            };
                        }, pagination: false, scroll: { y: 500 } }) })] }));
    };
    const rightCont = () => {
        return (_jsxs("div", { className: "import-excel-right", children: [_jsxs("div", { className: "excel-content", children: [_jsx("div", { className: "excel-title", children: "Excel\u5B57\u6BB5" }), _jsx("div", { className: "excel-table-content", children: renderExcelRow() })] }), _jsxs("div", { className: "note-content", children: [_jsx("div", { className: "excel-title", children: "\u7CFB\u7EDF\u5B57\u6BB5" }), _jsx("div", { className: "note-table-content", children: renderSystemRow() })] })] }));
    };
    //渲染重复提示
    const renderRepeatTip = () => {
        if (!repeatImportData || !repeatImportData.length) {
            return;
        }
        let dataSource = [];
        const columns = [
            {
                title: "页签名称",
                dataIndex: "sheetName",
                key: "sheetName",
            },
            {
                title: "节点名称",
                dataIndex: "noteName",
                key: "noteName",
            },
            {
                title: "重复主键",
                dataIndex: "rmap",
                key: "rmap",
            },
            {
                title: "重复行号",
                width: 160,
                dataIndex: "rowIndex",
                key: "rowIndex",
            },
            {
                title: "对应项目列",
                dataIndex: "projectName",
                key: "projectName",
                width: 290,
            },
        ];
        for (let i = 0; i < repeatImportData.length; i++) {
            const { repIndex, index, projectCol, noteName, key, sheetName } = repeatImportData[i];
            dataSource.push({
                key: i,
                rmap: key,
                rowIndex: `第${index.join(",")}行重复`,
                projectName: projectCol.join(" | "),
                noteName: noteName,
                sheetName,
            });
        }
        return (_jsx(Modal, { title: "提示", open: repeatExcelModalShow, maskClosable: false, cancelText: "我知道了", okText: "强制导入", width: 1000, onOk: () => {
                setRepeatExcelModalShow(false);
                setImportExcelModalShow(true);
                setForceImport(true);
            }, onCancel: () => {
                setRepeatExcelModalShow(false);
                setForceImport(false);
            }, children: _jsxs(_Fragment, { children: [_jsxs("p", { children: [_jsx("b", { children: "\u65E0\u6CD5\u4FDD\u5B58" }), ",\u9879\u76EE\u5217\u91CD\u590D\u4E86! \u8BF7\u5230Excel\u4E2D\u4FEE\u6539\u91CD\u590D\u7684\u9879\u76EE\u5217\u540D\u79F0~"] }), _jsx("p", { style: { paddingBottom: 10 }, children: "\u5F3A\u5236\u5BFC\u5165\u7CFB\u7EDF\u4F1A\u4FEE\u6539\u4E3B\u952E\u540D\u79F0\u548C\u9879\u76EE\u540D\u79F0~" }), _jsx(Table, { dataSource: dataSource, columns: columns })] }) }));
    };
    const sysName = getCurrentSysName();
    return (_jsxs(_Fragment, { children: [renderRepeatTip(), _jsx(Modal, { title: title, open: importExcelModalShow, maskClosable: false, width: "80%", centered: true, destroyOnClose: true, className: "import-excel", onCancel: onCancel, footer: [
                    _jsxs("div", { className: adjustTipInfo
                            ? "import-footer-lf import-footer-tip"
                            : "import-footer-lf", children: [_jsxs("p", { children: [_jsx(ExclamationCircleOutlined, { style: { color: "orange" } }), " ", "\u6A21\u677F\u4E2D\u4EC5\u6807\u8BB0\u201C\u884C\u805A\u5408\u8C41\u514D\u5217\u201D\u53CA\u201C\u8FD0\u7B97\u7B26\u201D\u7684Excel\u516C\u5F0F\u53EF\u5BFC\u5165\u7CFB\u7EDF\uFF0C\u5176\u4F59\u5C06\u4EE5\u9759\u6001\u6570\u5F62\u5F0F\u5BFC\u5165\u7CFB\u7EDF~"] }), adjustTipInfo ? (_jsxs("p", { className: "show-tip", children: [_jsx(ExclamationCircleOutlined, { style: { color: "red" } }), " ", adjustTipInfo] })) : null, sysName === SystemName.MERGE && currentTname === "试算平衡" ? (_jsxs("p", { children: [_jsx(ExclamationCircleOutlined, { style: { color: "orange" } }), " ", "\u8BF7\u624B\u52A8\u53D6\u6D88\u8BD5\u7B97\u5E73\u8861\u8868\u3010\u5408\u5E76\u5C42\u3011\u201D\u5408\u5E76\u6570\u201C\u3001\u3010\u5408\u5E76\u5C42\u3011\u53CA\u3010\u5355\u4F53\u5C42\u3011\u201D\u5408\u5E76\u7528\u5355\u4F53\u6570\u201D\u3001\u5217\u7684\u5BF9\u5E94\uFF0C\u5426\u5219\u5C06\u4F1A\u51B2\u6389\u5408\u5E76\u6A21\u677F\u4E2D\u8FD9\u4E9B\u5217\u7684\u516C\u5F0F"] })) : null] }),
                    _jsxs("div", { className: adjustTipInfo
                            ? "import-footer-ri import-footer-ri-tip"
                            : "import-footer-ri", children: [_jsx(Button, { onClick: onCancel, children: "\u53D6\u6D88" }, "continue"), _jsx(Button, { type: "primary", onClick: onConfirm, loading: btnLoading, children: "\u6267\u884C\u5BFC\u5165" }, "confirm")] }),
                ], children: _jsx(Spin, { spinning: isLoading, delay: 500, tip: "\u00A0\u00A0\u6B63\u5728\u5BFC\u5165\uFF5E", children: _jsx("div", { className: "import-excel-body", children: _jsx(LayoutB, { leftSlot: leftCont(), rightSlot: rightCont(), rowSize: ["30%", "20px", "70%"] }) }) }) })] }));
});
export default ImportExcelModal;
